#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author:Charmander

import os

import requests
from xlrd import open_workbook

from Advisement_player import readConfig as readConfig
from Advisement_player.common.log import MyLog as Log

localReadConfig = readConfig.ReadConfig()
log = Log.get_log()
logger = log.get_logger()
proDir = readConfig.proDir

def get_visitor_token():
    """
    create a token for visitor
    :return:
    """
    host = localReadConfig.get_http("BASEURL")
    response = requests.get(host+"/v1/user/signIn")
    info = response.json()
    token = info.get("info")
    logger.debug("Create token:%s" % (token))
    return token

def set_visitor_token_to_config():
    """
    set token that created for visitor to config
    :return:
    """
    token_v = get_visitor_token()
    localReadConfig.set_headers("TOKEN_V", token_v)


def get_xls(xls_name,sheet_name):
    cls = []
    #获取xls
    xlsPath = os.path.join(proDir,'testFile',xls_name)
    file = open_workbook(xlsPath)
    sheet = file.sheet_by_name(sheet_name)
    #行数
    nrows = sheet.nrows
    for i in range(nrows):
        if sheet.row_values(i)[0] != u'case_name':
            cls.append(sheet.row_values(i))
            print(cls)
    return cls

def get_value_from_return_json(json, data):
    info = json['data']
    value = info[data]
    return value



if __name__=='__main__':
    print(get_xls('login'))
    set_visitor_token_to_config()